<template>
	<view class="">
		<view class="u-padding-20">
			<u-form :model="form" ref="uForm" label-width="160">
				<u-form-item label="企业名称" prop="name">
					<u-input v-model="form.name" placeholder="请输入店铺名称" />
				</u-form-item>
				<u-form-item label="联系人" prop="contacts">
					<u-input v-model="form.contacts" type="Number" placeholder="请输入联系人" />
				</u-form-item>
				<u-form-item label="联系号码" prop="phone">
					<u-input v-model="form.phone" type="Number" placeholder="请输入联系号码" />
				</u-form-item>

				<u-form-item label="企业介绍" label-position="top">
					<u-input :customStyle="{background:'#f7f7f7',padding:'20rpx'}" v-model="form.com_introduce"
						type="textarea" placeholder="请输入企业介绍" />
				</u-form-item>


				<u-form-item label="业务介绍" label-position="top">
					<u-input :customStyle="{background:'#f7f7f7',padding:'20rpx'}" v-model="form.business_introduce"
						type="textarea" placeholder="请输入业务介绍" />
				</u-form-item>

				<view class="u-margin-top-20">营业执照</view>
				<view class="u-flex">
					<u-form-item :border-bottom="false" prop='business_license' label-position="top">
						<w-upload :Number='1' v-model="form.business_license" text="营业执照" width="300"></w-upload>
					</u-form-item>

				</view>

				<view class="u-margin-top-20">相关资质</view>
				<view class="u-flex">
					<u-form-item :border-bottom="false" prop='qualification' label-position="top">
						<w-upload :Number='1' v-model="form.qualification" text="营业执照" width="300"></w-upload>
					</u-form-item>

				</view>




			</u-form>
		</view>
<view class="" style="width: 600rpx;margin:40rpx auto;font-size: 20rpx;">
				<u-checkbox-group>
					<u-checkbox v-model="isread" :label-disabled="true">
						请认真阅读<text @click="read(17)">《用户服务协议及隐私政策》</text>
						</u-checkbox>
				</u-checkbox-group>
			</view>
			
			
		<view style="width: 90%;margin: 40rpx auto;">
			<u-button @click="submit" type="primary" shape="circle">提交</u-button>
		</view>


		<u-toast ref="uToast" />


	</view>
</template>

<script>
	import wxpay from '@/common/wxpay.js';
	export default {
		data() {
			return {
				isread:false,
				form: {
					name: '',
					phone: "",
					contacts: '',
					com_introduce: "",
					business_license: [],
					qualification: [],
					business_introduce: "",
					type: 2
				},
				rules: {
					name: [{

						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],

					contacts: [{
						required: true,
						message: '请输入联系人',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],


					business_license: [{
						validator: (rule, value, callback) => {
							if (value.length) {
								return true;
							} else {
								return false;
							}
						},
						message: '请上传营业执照',
						trigger: ['change', 'blur'],
					}],


					qualification: [{
						validator: (rule, value, callback) => {
							if (value.length) {
								return true;
							} else {
								return false;
							}
						},
						message: '请上传企业资质',
						trigger: ['change', 'blur'],
					}],


					phone: [{
							required: true,
							message: '请输入手机号',
							trigger: ['change', 'blur'],
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								// 上面有说，返回true表示校验通过，返回false表示不通过
								// this.$u.test.mobile()就是返回true或者false的
								return this.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							// 触发器可以同时用blur和change
							trigger: ['change', 'blur'],
						}
					]
				}
			};
		},
		methods: {
			
			read(e){
				uni.navigateTo({
					url:'../about/index?id='+e
				})
			},
			
			
			submit() {
if(!this.isread){
				   this.$u.toast("请认真阅读协议")
				   return
			}
				this.$refs.uForm.validate(valid => {
					if (valid) {

						this.$u.post('/user/apply', this.form).then(res => {
							const wx = new wxpay(res);
							wx.pay().then(res => {
								this.$refs.uToast.show({
									title: '提交成功',
									type: 'success',
									back: true
								})
							}).catch(err => {

							})


						}).catch(err => {

						})
					} else {
						console.log('验证失败');
					}
				});
			}
		},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	};
</script>


<style scoped>

</style>
